<!--#include file="common/header.html"-->
<body>

    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <!--头部搜索-->
                <section class="panel panel-padding">
                    <form class="layui-form" action="/education/admin/productGroup">
                        <input type="hidden" name="_query.groupId" id="queryGroupId">
                        <div class="layui-form">
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="_query.keyword" placeholder="关键字" id="queryKeyword">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button lay-submit class="layui-btn" lay-filter="search">查找</button>
                            </div>
                        </div>
                    </form>
                </section>

                <!--列表-->
                <section class="panel panel-padding">
                    <div class="group-button">
                        <button class="layui-btn layui-btn-small modal-catch"
                                data-params='{"content":".add-subcat", "title":"添加","type":"1", "maxmin":"true"}'>
                            <i class="iconfont">&#xe649;</i> 添加
                        </button>
                        <!--<button class="layui-btn layui-btn-small" onclick="viewDetail();">
                            <i class="iconfont">&#xe653;</i>编辑
                        </button>-->
                        <button class="layui-btn layui-btn-small layui-btn-danger ajax-all" data-name="checkbox"
                                data-params='{"url": "/education/admin/productGroup/delete"}'>
                            <i class="iconfont">&#xe626;</i> 删除
                        </button>
                    </div>
                    <div id="list" class="layui-form"></div>

                    <div class="text-right" id="page"></div>
                </section>
            </div>
        </div>
    </div>
    <div class="add-subcat">
        <form class="layui-form layui-form-pane" action="/education/admin/productGroup/save" id="form1">
            <input type="hidden" name="id">
            <input type="hidden" name="groupId" id="groupId"/>
            <div class="layui-form-item">
                <label class="layui-form-label">产品编号</label>
                <div class="layui-input-inline">
                    <input type="text" name="productNo1" placeholder="请输入产品编号" id="autocompleteInput"
                           jq-verify="required"  autocomplete="false" class="layui-input">
                    <input type="hidden" name="productNo" id="pno">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline">
                    <input type="number" name="ord" required jq-verify="required" jq-error="排序必须为数字" value="0"
                           class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" jq-submit jq-filter="submit" before-fun="beforeSubmit();">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>

</body>
<script id="list-tpl" type="text/html"
        data-params='{"url":"/education/admin/productGroup","dataName":"productGroupData","pageid":"#page", "method":"post"}'>
    <table id="example" class="layui-table lay-even" data-name="productGroupData" data-tplid="list-tpl">
        <thead>
        <tr>
            <th width="30"><input type="checkbox" id="checkall" data-name="checkbox" lay-filter="check"
                                  lay-skin="primary"></th>
            <th>专场名</th>
            <th>产品名</th>
            <th width="150">产品编号</th>
            <th width="150">产品图片</th>
            <th width="80">排序</th>
            <th width="170">添加时间</th>
            <!--<th width="200">操作</th>-->
        </tr>
        </thead>
        <tbody>
        {{# layui.each(d.list, function(index, item){ }}
        <tr>
            <td><input type="checkbox" name="checkbox" value="{{ item.id}}" lay-skin="primary"></td>
            <td>{{ item.group_name }}</td>
            <td>
                {{ item.product_name||'' }}
            </td>
            <td>
                {{ item.product_no||'' }}
            </td>
            <td>
                <img src="/education{{ item.cover_image }}" alt="..." class="img-thumbnail">
            </td>
            <td class="edit" data-list='{"key":"id={{ item.id}}","filed":"ord","render":"true"}'
                data-params='{"url":"/education/admin/productGroup/update/{{item.id}}", "data":"id={{ item.id}}" }'>
                {{ item.ord||'' }}
            </td>
            <td>{{ item.create_time||'' }}</td>
        </tr>
        {{# }); }}
        </tbody>

    </table>
</script>
<!--<script src="../js/layui/layui.js"></script>-->
<script type="text/javascript" src="../js/lib/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../js/lib/rest.js"></script>
<script type="text/javascript" src="../js/lib/bootstrap.autocomplete.js"></script>
<!--#include file="common/version.html"-->
<script>
    function beforeSubmit(){
        $('#groupId').val(gid);
        $('#queryGroupId').val(gid);
        if(gid == 0){
            alert('请选择对应的子栏目');
            return 0;
        }
        if(!$('#pno').val()){
            alert('请选择正确的商品');
            return 0;
        }
        return 1;
    }

    $(function(){
        $('#autocompleteInput').autocomplete({
            source:function(query,process){
                var matchCount = this.options.items;//返回结果集最大数量
                $.post("/education/admin/product/query",{"keyword":query},function(respData){
                    console.log(respData);
                    if(respData.code == 200) {
                        return process(respData.data);
                    }
                });
            },
            formatItem:function(item){
                var name = item["product_name"] || '';
                var username = item["product_no"] || '';
                return name +"("+ username + ")";
            },
            setValue:function(item){
                return {'data-value':item["product_name"],'real-value':item["product_no"], };
            },
            afterSelect: function (v, rv) {
                var pid = rv.split('-')[0];
                $('#pno').val(pid);
            }
        });
    });
</script>

</html>